package com.sharecode.stock.controller;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import com.alibaba.fastjson.JSONObject;
import com.sharecode.stock.aop.RestResult;
import com.sharecode.stock.exception.StockException;

import lombok.extern.java.Log;

@ControllerAdvice
@Log
public class ErrorControllerAdvice {

	@ExceptionHandler(Exception.class)
    public Object customException(Exception e) {
		RestResult<Object> result = new RestResult<>();
		result.setCode(10000);
		if (e instanceof StockException) {
			result.setMessage(e.getMessage());
		}
		log.info(JSONObject.toJSONString(result));
		return result;
    }
}
